import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import bean.Feriado;

public class PrevisaoPJ {

	
	
	public Map<String, Integer> previsao( Date dtIniPrm, Date dtFimPrm ){
		
		Map<String, Integer> mapa = new HashMap<String, Integer>();
		
		try {

			SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
			GregorianCalendar dtFim = new GregorianCalendar( );
			GregorianCalendar dtIni = new GregorianCalendar();
			List<String> lista_datas = new ArrayList<String>();
			
			dtFim.setTime( dtFimPrm );
			dtIni.setTime( dtIniPrm );
			
			
			System.out.println(df.format(dtFim.getTime()));
			System.out.println(df.format(dtIni.getTime()));
			
			Feriado f = new Feriado();
			
		 
			lista_datas.add( "28/07/2012");
			lista_datas.add( "29/07/2012");
		
			dtIni.set(2012, 5 - 1, 21);
			dtFim.set(2012, 8 - 1, 20);

			int dif = 0, sunday = 0, saturday = 0, feriado=0;

			System.out.println("De " + df.format(dtIni.getTime()) + " Ate "	+ df.format(dtFim.getTime()));

			while (  dtFim.after( dtIni ) ) {
				dtIni.add(GregorianCalendar.DAY_OF_MONTH, 1);
				
				if (dtIni.get(GregorianCalendar.DAY_OF_WEEK) != GregorianCalendar.SUNDAY
						&& dtIni.get(GregorianCalendar.DAY_OF_WEEK) != GregorianCalendar.SATURDAY)
					dif++;

				if (dtIni.get(GregorianCalendar.DAY_OF_WEEK) == GregorianCalendar.SUNDAY)
					sunday++;

				if (dtIni.get(GregorianCalendar.DAY_OF_WEEK) == GregorianCalendar.SATURDAY)
					saturday++;
				
				if ( lista_datas.contains( df.format( dtIni.getTime()))){
                      feriado++;					
				}
			}
			mapa.put("domingos", sunday);
			mapa.put("sabados", saturday);
			mapa.put("semana", dif);
			mapa.put("feriados", feriado);
			
		} catch (Exception e) {
			System.out.println(e);
			System.exit(0);
		}
		return mapa;
	}

}
